package com.freshcity.page.help
{
	import com.freshcity.common.QuestionWin;
	import com.freshcity.component.alert.Alert;
	import com.freshcity.component.container.Component;
	import com.freshcity.core.GlobalVar;
	import com.freshcity.core.MainScene;
	import com.freshcity.core.OpCodes;
	import com.freshcity.utils.StringUtil;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextFormat;
	
	public class UserQuestion extends Component
	{
		private var back:QuestionWin;
		
		public function UserQuestion(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
		{
			this.visible=false;
			super(parent, xpos, ypos);
			back.confirmBtn.addEventListener(MouseEvent.CLICK,onSubmitData);
		}
		
		protected function onLink(event:TextEvent):void
		{
			var url:URLRequest = new URLRequest("http://browser.baoku.360.cn/app/show?appid=102233619"); 
			navigateToURL(url,"_blank");
		}
		
		override public function destroy():void
		{
			back.confirmBtn.removeEventListener(MouseEvent.CLICK,onSubmitData);
			this.parent.removeChild(this);
		}
		
		protected function onSubmitData(event:MouseEvent):void
		{
			var s:String = StringUtil.trim(back.words.text)
			if(s.length<2){
				main.msg.showRollTipsMsg("内容过于简单");
			}else{
				var uid:String = GlobalVar.SUPPORT_ID;
				main.commu.send(OpCodes.WRITE_MSG,{t:uid,c:s,r:false},onWriteMsg);
				back.confirmBtn.enabled=false;
			}
		}
		
		private function onWriteMsg(data:*):void
		{
			main.commu.unRegister(OpCodes.WRITE_MSG);
			back.confirmBtn.enabled = true;
			if(data is String){
				main.msg.showRollTipsMsg(data);
			}else{
				var htmlContent:String="感谢支持！您的意见对我们很重要，请保持关注。";
				var myfun:Function = function(arg1:int):void{
					if (arg1 == Alert.OK)
					{
						back.words.text="";
					}
				};
				
				Alert.show(htmlContent, "", Alert.OK, null, myfun);
			}
		}		
		
		override protected function addChildren():void
		{
			super.addChildren();
			back = new QuestionWin();
			var tf:TextFormat = new TextFormat("宋体",14,0);
			tf.leading = 6;
			back.words.textField.defaultTextFormat=tf;
			
			back.noAdviceLink.styleSheet = StringUtil.style;
			back.noAdviceLink.x = 200;
			back.noAdviceLink.width = 400;
			back.noAdviceLink.visible = false;
			back.noAdviceLink.htmlText="".concat("<a href='event:","","'>","没意见？来给我们加油吧！","</a>");
			back.noAdviceLink.addEventListener(TextEvent.LINK,onLink);
			addChild(back);
		}
		
		override public function draw():void
		{
			super.draw();
		}
		
		
	}
}